import collections
class Solution(object):
    def tupleSameProduct(self, nums):
        n = len(nums)
        d = collections.defaultdict(int)
        for i in range(n):
            for j in range(i + 1, n):
                d[nums[i] * nums[j]] += 1
        ans = 0
        for key in d:
            ans += d[key] * (d[key] - 1) * 4
        return ans


